package com.itheima.consumer.listeners;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MqListener {

//    @RabbitListener(queues = "simple.queue")
//    public void listenSimpleQueue(String msg) {
//        System.out.println("消费者收到了simple.queue的消息：【" + msg + "】");
//    }
//
//    /**
//     * fanout 消费者
//     *
//     * @param msg
//     * @
//     */
//    @RabbitListener(queues = "fanout.queue1")
//    public void listenFanoutQueue1(String msg) {
//        System.out.println("消费者1 收到了 fanout.queue1的消息：【" + msg + "】");
//    }
//
//    @RabbitListener(queues = "fanout.queue2")
//    public void listenFanoutQueue2(String msg) {
//        System.out.println("消费者2 收到了 fanout.queue2的消息：【" + msg + "】");
//    }

    /**
     * Direct 消费者
     *
     * @param msg
     * @
     */
    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "direct.queue1", durable = "true"), exchange = @Exchange(name = "hmall.direct", type = ExchangeTypes.DIRECT), key = "red"))
    public void listenDirectQueue1(String msg) {
        System.out.println("消费者1 收到了routingkey为red direct.queue1的消息：【" + msg + "】");
    }

    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "direct.queue2", durable = "truw"), exchange = @Exchange(name = "hmall.direct", type = ExchangeTypes.DIRECT), key = "blue"))
    public void listenDirectQueue2(String msg) {
        System.out.println("消费者2 收到了routingkey为blue direct.queue1的消息：【" + msg + "】");
    }

    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "direct.queue3", durable = "true"), exchange = @Exchange(name = "hmall.direct", type = ExchangeTypes.DIRECT), key = {"red", "blue"}))
    public void listenDirectQueue3(String msg) {
        System.out.println("消费者3 收到了routingkey为red和blue direct.queue1的消息：【" + msg + "】");
    }

//    /**
//     * Topic 消费者
//     */
//    @RabbitListener(queues = "topic.queue1")
//    public void listenTopicQueue1(String msg) {
//        System.out.println("消费者1 收到了 topic.queue1的消息：【" + msg + "】");
//    }
//
//    @RabbitListener(queues = "topic.queue2")
//    public void listenTopicQueue2(String msg) {
//        System.out.println("消费者2 收到了 topic.queue2的消息：【" + msg + "】");
//    }
//
//    /**
//     * LazyQueue模式
//     *
//     * @param msg
//     */
//    @RabbitListener(queues = "lazy.queue")
//    public void listLazyQueue(Map<String, Object> msg) {
//        int i = 1 / 0;
//        System.out.println("消费者2 收到了 topic.queue2的消息：【" + msg + "】");
//    }

//
//    /**
//     * 延迟消息消费
//     *
//     * @param msg
//     */
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "delay.queue", durable = "true"),
//            exchange = @Exchange(name = "delay.direct", delayed = "true"),
//            key = {"delay"}
//    ))
//    public void listDelayQueue(Map<String, Object> msg) {
//        System.out.println("消费者2 收到了 topic.queue2的消息：【" + msg + "】");
//    }

//    /**
//     * LazyQueue模式:通过交换机  TODO
//     *
//     * @param msg
//     */
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "lazy.queue", durable = "true"),
//            exchange = @Exchange(name = "hmall.topic", type = ExchangeTypes.TOPIC),
//            key = "simple"
//    ))
//    public void listLazyQueueByExchange(String msg) {
//        System.out.println("消费者2 收到了 lazy.queue消息是单数的消息：【" + msg + "】");
//    }

    //======================消息转换器=======================================//
//    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "object.queue", durable = "true"), exchange = @Exchange(name = "hmall.topic", type = ExchangeTypes.TOPIC), key = "object.queue"))
//    public void listenMessageCoverQueue2(Map<String, Object> msg) {
//        System.out.println("消费者2 收到了 topic.queue2的消息：【" + msg + "】");
//    }
}
